package pearson.automation.forms.courseDetails;

/*
  Buldings: (type: qty, level)
  Apartments: 4, all lvl 4
  Steel Mill: 5, all lvl 4
  Restaurants: 4 lvl 4, 1 lvl 5
  Hideout: 5 lvl 4, 1 lvl 5
  Cement: 5 lvl 4
  
  Stats:
  Cash: 4k, 12k/hr
  Food: 8k, 9k/hr
  Steel: 39k, 8k/hr
  Cement: 35k, 5k/hr
 */
import org.openqa.selenium.By;

import framework.elements.Button;

import pearson.automation.forms.BaseFormWithSidebars;

public class CoursePreview extends BaseFormWithSidebars {

    private static Button publish = new Button(By.linkText("Publish Course"), "Publish");
    
    private Button book    = new Button(By.className("output-preview-book-icon"), "Book");
    private Button tablet  = new Button(By.className("output-preview-tablet-icon"), "Tablet");
    private Button ereader = new Button(By.className("output-preview-ereader-icon"), "eReader");
    private Button html    = new Button(By.className("output-preview-html-icon"), "HTML");
    private Button lms     = new Button(By.linkText("LMS"), "LMS");
    
    public enum PreviewButton {
        BOOK, TABLET, EREADER, HTML, LMS
        };
    
    public CoursePreview() {
        super(publish.getLocator(), "Preview");
    }

    public CoursePublish clickPublish() {
        publish.clickAndWait();
        return new CoursePublish();
    }
    
    public boolean isButtonEnabled(PreviewButton button) {
        boolean result = false;
        switch(button) {
            case BOOK: 
                result = !book.getElement().getAttribute("class").contains("disabled"); break;
            case TABLET: 
                result = !tablet.getElement().getAttribute("class").contains("disabled"); break;
            case EREADER: 
                result = !ereader.getElement().getAttribute("class").contains("disabled"); break;
            case HTML: 
                result = !html.getElement().getAttribute("class").contains("disabled"); break;
            case LMS: 
                result = !lms.getElement().getAttribute("class").contains("disabled"); break;
        }
        return result;
    }
    
    public PreviewButton getSelectedButton() {
        if (tablet.getElement().getAttribute("class").contains("selected")) {
            return PreviewButton.TABLET;
        }
        if (html.getElement().getAttribute("class").contains("selected")) {
            return PreviewButton.HTML;
        }
        if (lms.getElement().getAttribute("class").contains("selected")) {
            return PreviewButton.LMS;
        }
        return null;
    }
    
    public void clickButton(PreviewButton button) {
        switch(button) {
            case TABLET: 
                tablet.clickAndWait(); break;
            case HTML: 
                html.clickAndWait(); break;
            case LMS: 
                lms.clickAndWait(); break;
        }
    }

}
